package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.ToothDetailsActivity;
import com.fancy.learncenter.activity.TzDetailActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.CollectDataBean;
import com.fancy.learncenter.bean.GzListDataBean;
import com.fancy.learncenter.bean.TzDataBean;
import com.superservice.lya.R;

import java.util.ArrayList;

/**
 * Created by hyy on 2018/1/27.
 * Explain activity as
 */

public class CollectToothTZAdapter extends CommonRecycleViewAdapter<CollectDataBean> {
    public CollectToothTZAdapter(Context mContext, ArrayList<CollectDataBean> itemDatas) {
        super(mContext, R.layout.fragment_ygt_gz_list, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CollectDataBean item, int position) {

        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        SimpleDraweeView answer_icon = customViewHold.getView(R.id.answer_icon);
        simpleDraweeView.setImageURI(item.getImgsrc());


        TextView name = customViewHold.getView(R.id.name);
        name.setText(item.getNick_name());


        TextView content = customViewHold.getView(R.id.content);
        content.setText(item.getTitle());
//
        TextView islove = customViewHold.getView(R.id.islove);
        TextView flag1 = customViewHold.getView(R.id.flag1);
        TextView answer_name = customViewHold.getView(R.id.answer_name);
        TextView question_num = customViewHold.getView(R.id.question_num);
//
        LinearLayout pic_ll = customViewHold.getView(R.id.pic_ll);
//        RecyclerView recyclerView = customViewHold.getView(R.id.recycleView);

//        帖子
        if ("5".equals(item.getType())) {
//            recyclerView.setVisibility(View.VISIBLE);
            islove.setVisibility(View.GONE);
            flag1.setVisibility(View.GONE);
            question_num.setText(item.getComment_num() + "回帖");

            if (item.getImglist() != null && item.getImglist().size() > 0) {

                SimpleDraweeView pic_1 = customViewHold.getView(R.id.pic_1);
                SimpleDraweeView pic_2 = customViewHold.getView(R.id.pic_2);
                SimpleDraweeView pic_3 = customViewHold.getView(R.id.pic_3);

                if (item.getImglist() != null) {

                    if (item.getImglist().size() == 1) {
                        pic_1.setVisibility(View.VISIBLE);
                        pic_2.setVisibility(View.INVISIBLE);
                        pic_3.setVisibility(View.INVISIBLE);

                        pic_1.setImageURI(item.getImglist().get(0));
                    } else if (item.getImglist().size() == 2) {
                        pic_1.setVisibility(View.VISIBLE);
                        pic_2.setVisibility(View.VISIBLE);
                        pic_3.setVisibility(View.INVISIBLE);

                        pic_1.setImageURI(item.getImglist().get(0));
                        pic_2.setImageURI(item.getImglist().get(1));
                    } else if ((item.getImglist().size() >= 3)) {
                        pic_1.setVisibility(View.VISIBLE);
                        pic_2.setVisibility(View.VISIBLE);
                        pic_3.setVisibility(View.VISIBLE);

                        pic_1.setImageURI(item.getImglist().get(0));
                        pic_2.setImageURI(item.getImglist().get(1));
                        pic_3.setImageURI(item.getImglist().get(2));
                    }

                } else {
                    pic_1.setVisibility(View.GONE);
                    pic_2.setVisibility(View.GONE);
                    pic_3.setVisibility(View.GONE);
                }
//                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
//                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//                recyclerView.setLayoutManager(linearLayoutManager);
//
//
//                recyclerView.setAdapter(new CommonRecycleViewAdapter<String>(mContext, R.layout.tz_pic_item, (ArrayList<String>) item.getImglist()) {
//                    @Override
//                    public void bindView(CustomViewHold customViewHold, String item, int position) {
//
//                        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
//                        simpleDraweeView.setImageURI(item);
//
//                    }
//                });

            }
            customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, TzDetailActivity.class);

                    intent.putExtra("wdListDataBean", item.getId());

                    mContext.startActivity(intent);
                }
            });
        }
//        问答
        else if ("4".equals(item.getType())) {
            pic_ll.setVisibility(View.GONE);
            flag1.setVisibility(View.VISIBLE);
            question_num.setText(item.getComment_num() + "人回答");
            if ("1".equals(item.getStatus())) {
                flag1.setText("已解决");
                islove.setVisibility(View.VISIBLE);
                islove.setText(item.getSolve().getContentX());
                answer_icon.setVisibility(View.VISIBLE);
                answer_icon.setImageURI(item.getSolve().getComment_user_img());

                customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, ToothDetailsActivity.class);
                        intent.putExtra("wdListDataBean", item.getId());
                        intent.putExtra("solve_id", item.getSolve().getIdX());
                        mContext.startActivity(intent);
                    }
                });

            } else {
                flag1.setText("问.未解决");
                islove.setVisibility(View.GONE);

                answer_icon.setVisibility(View.GONE);

                customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, ToothDetailsActivity.class);
                        intent.putExtra("wdListDataBean", item.getId());
                        mContext.startActivity(intent);
                    }
                });
            }


        }

    }
}
